/* Yet Another Experimental Software Renderer
 *
 * Copyright (c) 2010 Pawel "Hery" Dziepak
 */

#include "function_input.h"

using namespace yaesr;

void function_input::begin(primitive_type tpe) {
	Assert(!receiving_data);

	p_type = tpe;
	receiving_data = true;
}

void function_input::set_vertex(double x, double y, double z) {
	Assert(receiving_data);

	vertex vert;
	vert.position = vec4(x, y, z, 1.0);
	vertices.push_back(vert);
}

void function_input::set_color(double a, double r, double g, double b) {
	Assert(receiving_data);
	Assert(vertices.size() > 0);

	vertices.back().color0 = color(a, r, g, b);
}

void function_input::set_texccord(double u, double v) {
	Assert(receiving_data);
	Assert(vertices.size() > 0);

	vertices.back().texcoord0 = vec2(u, v);
}

void function_input::end() {
	Assert(receiving_data);
	Assert(next != NULL);

	next->set_type(p_type);
	next->write_data(vertices);

	vertices.clear();
	receiving_data = false;
}